- Notifications
You must be signed in to change notification settings - Fork 31
/
Copy path137. Single Number II.c
32 lines (22 loc) · 682 Bytes
/
137. Single Number II.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
137. Single Number II
Given an array of integers, every element appears three times except for one, which appears exactly once. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
*/
intsingleNumber(int*nums, intnumsSize) {
inti, ones, twos;
ones=twos=0;
for (i=0; i<numsSize; i++) {
ones= (ones ^ nums[i]) & ~twos;
twos= (twos ^ nums[i]) & ~ones;
}
returnones;
}
/*
Difficulty:Medium
Total Accepted:119.8K
Total Submissions:288.6K
Related Topics Bit Manipulation
Similar Questions Single Number Single Number III
*/